﻿<form class="layui-form layui-form-pane" lay-filter="">
    <div class="layui-form-item">
        <label class="layui-form-label">上级模块</label>
        <div class="layui-input-inline">
            <div id="moduleSelect"></div>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">模块类型</label>
        <div class="layui-input-blcok">
            <input type="radio" name="ResourceType" value="1" title="菜单" checked>
            <input type="radio" name="ResourceType" value="2" title="按钮">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">模块名称</label>
        <div class="layui-input-block">
            <input type="text" name="ResourceName" maxlength="50" autocomplete="off" class="layui-input" lay-verify="required" />
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">模块链接</label>
        <div class="layui-input-block">
            <input type="text" name="ResourceUrl" maxlength="50" autocomplete="off" class="layui-input" />
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">模块图标</label>
        <div class="layui-input-block">
            <input type="text" name="ResourceIcon" maxlength="50" autocomplete="off" class="layui-input" />
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">模块状态</label>
        <div class="layui-input-block">
            <input type="radio" name="ResourceState" value="True" title="启用" checked>
            <input type="radio" name="ResourceState" value="False" title="关闭">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">模块排序</label>
        <div class="layui-input-block">
            <input type="text" name="SortNumber" autocomplete="off" class="layui-input" />
        </div>
    </div>
    <div class="layui-form-item" style="text-align:center;">
        <button class="layui-btn" lay-submit lay-filter="save">保存</button>
        <button class="layui-btn" id="cancel">取消</button>
    </div>
</form>

@section Scripts{
<script src="/lib/xm-select.js"></script>
<script type="text/javascript">
    layui.use(function() {
        var form = layui.form;
        var $ = layui.jquery;
        var xm = xmSelect.render({
            el: '#moduleSelect',
            name: 'ParentId', //提交表单数据的值
            filterable: true,
            model: {
                label: {
                    type: 'text'
                }
            },
            prop: {
                name: 'ResourceName',
                value: 'Id'
            },
            radio: true,
            clickClose: true,
            tree: {
                show: true,
                strict: false,
                expandedKeys: true,
            },
            height: 'auto',
            data: []
        })
        $.ajax({
            url: '/SysResource/Index',
            success: function(res) {
                if (res.Code == 200) {
                    xm.update({
                        data: xmSelect.arr2tree(res.Data, 'ParentId', 'Id', 'children', 0)
                    })
                    xm.setValue([@ViewBag.parentId])
                }
            }
        });
        form.on("submit(save)", function(formdata) {
            $.ajax({
                url: '/SysResource/Add',
                data: formdata.field,
                success: function(res) {
                    if (res.Code == 200) {
                        layer.msg('保存成功', {
                            time: 1000
                        }, function() {
                            parent.layer.closeAll('iframe');
                        });
                    } else {
                        layer.msg(res.Message);
                    }
                }
            });
            return false;
        })
        $("#cancel").click(function() {
            parent.layer.closeAll();
            return false;
        })
    })
</script>
}